package org.softmed.filehandling.selectors;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class JavaFileSelector implements FileSelector {

	@Override
	public boolean isFileSelected(String fileName, String pckgname) {
		if (fileName.endsWith(".class"))
			return true;
		else
			return false;
	}

	@Override
	public Class processFile(String fileName, String pckgname)
			throws ClassNotFoundException {
		return Class.forName(pckgname + '.'
				+ fileName.substring(0, fileName.length() - 6));
	}

	@Override
	public Class processJarFile(JarFile jarFile, JarEntry jarEntry, String path)
			throws Throwable {
		String jarName = jarEntry.getName();
		if (jarName.endsWith(".class")) {
			String className = jarName.replaceAll("/", ".");
			className = className.replace(".class", "");
			return Class.forName(className);
		}

		return null;
	}
}
